package com.eshop.modules.shop.service.impl;

import java.io.IOException;
import java.util.Iterator;
import com.eshop.utils.FileUtil;
import java.util.ArrayList;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.eshop.common.utils.QueryHelpPlus;
import com.eshop.modules.shop.service.dto.MaterialGroupDto;
import java.util.LinkedHashMap;
import java.util.List;
import com.github.pagehelper.PageInfo;
import java.util.Map;
import org.springframework.data.domain.Pageable;
import com.eshop.modules.shop.service.dto.MaterialGroupQueryCriteria;
import com.eshop.dozer.service.IGenerator;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import com.eshop.modules.shop.service.MaterialGroupService;
import com.eshop.modules.shop.domain.MaterialGroup;
import com.eshop.modules.shop.service.mapper.MaterialGroupMapper;
import com.eshop.common.service.impl.BaseServiceImpl;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = { Exception.class })
public class MaterialGroupServiceImpl extends BaseServiceImpl<MaterialGroupMapper, MaterialGroup> implements MaterialGroupService
{
    private final IGenerator generator;
    
    public Map<String, Object> queryAll(final MaterialGroupQueryCriteria criteria, final Pageable pageable) {
        this.getPage(pageable);
        final PageInfo<MaterialGroup> page = (PageInfo<MaterialGroup>)new PageInfo((List)this.queryAll(criteria));
        final Map<String, Object> map = new LinkedHashMap<String, Object>(2);
        map.put("content", this.generator.convert(page.getList(), (Class)MaterialGroupDto.class));
        map.put("totalElements", page.getTotal());
        return map;
    }
    
    public List<MaterialGroup> queryAll(final MaterialGroupQueryCriteria criteria) {
        return (List<MaterialGroup>)((MaterialGroupMapper)this.baseMapper).selectList((Wrapper)QueryHelpPlus.getPredicate((Object)MaterialGroup.class, (Object)criteria));
    }
    
    public void download(final List<MaterialGroupDto> all, final HttpServletResponse response) throws IOException {
        final List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        for (final MaterialGroupDto yxMaterialGroup : all) {
            final Map<String, Object> map = new LinkedHashMap<String, Object>();
            map.put("创建时间", yxMaterialGroup.getCreateTime());
            map.put("创建者ID", yxMaterialGroup.getCreateId());
            map.put("分组名", yxMaterialGroup.getName());
            list.add(map);
        }
        FileUtil.downloadExcel((List)list, response);
    }
    
    public MaterialGroupServiceImpl(final IGenerator generator) {
        this.generator = generator;
    }
}
